﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyMainSite.Models;
using System.IO;
using DotNetX;
using System.Web.UI.WebControls;

namespace MyMainSite.Controllers
{
    public class QuickController : Controller
    {
	//    //
	//    // GET: /Quick/
	//    [ValidateInput(false)]
	//    public ActionResult Project()
	//    {
	//        RichardsSiteEntities dc = new RichardsSiteEntities();

	//        QuickProjectModel m = new QuickProjectModel();

	//        m.Projects = (from p in dc.Projects
	//                      select p).ToList();

	//        return View(m);
	//    }

	//    [ValidateInput(false)]
	//    public ActionResult Blogs()
	//    {
	//        RichardsSiteEntities dc = new RichardsSiteEntities();

	//        QuickBlogsModel m = new QuickBlogsModel();

	//        m.Blogs = (from b in dc.Blogs
	//                   select b).ToList();

	//        return View(m);
	//    }

	//    [HttpPost, ValidateInput(false)]
	//    public ActionResult Blogs(int? blogId, int? entryId, string textTitle, string textDescription, string textFriendlyUrl)
	//    {
	//        RichardsSiteEntities dc = new RichardsSiteEntities();

	//        BlogEntry be = null;

	//        if (entryId == null || entryId == 0)
	//        {
	//            Blog blog = (from b in dc.Blogs
	//                         where b.BlogId == blogId
	//                         select b).Single();

	//            be = new BlogEntry();
	//            blog.BlogEntries.Add(be);

	//            be.BlogId = blog.BlogId;
	//        }
	//        else
	//        {
	//            be = (from e in dc.BlogEntries
	//                  where e.BlogEntryId == entryId
	//                  select e).Single();
	//        }

	//        be.Title = textTitle;
	//        be.BodyHtml = textDescription;
	//        be.BodyText = textDescription.StripHtml();
	//        be.FriendlyUrl = textFriendlyUrl;
	//        be.DateCreated = DateTime.Now;

	//        dc.SaveChanges();

	//        QuickBlogsModel m = new QuickBlogsModel();

	//        m.Blogs = (from b in dc.Blogs
	//                   select b).ToList();

	//        return View(m);
	//    }

	//    [HttpPost, ValidateInput(false)]
	//    public ActionResult Project(int? projectId, string textName, string textDescription,
	//        string textSourceCodeUrl, string textFriendlyUrl)
	//    {
	//        Stream s = null;

	//        foreach (string file in Request.Files)
	//        {
	//            HttpPostedFileBase hpf = Request.Files[file];
	//            if (hpf.ContentLength == 0)
	//                continue;

	//            s = hpf.InputStream;
	//        }

	//        if (s == null)
	//            return View();

	//        BinaryReader reader = new BinaryReader(s);
	//        byte [] data = reader.ReadBytes((int)s.Length);

	//        RichardsSiteEntities dc = new RichardsSiteEntities();

	//        Project p = null;
	//        ProjectScreenShot ss = null;

	//        if (projectId == null || projectId == 0)
	//        {
	//            p = new Project();
	//            ss = new ProjectScreenShot();
	//        }
	//        else
	//        {
	//            p = (from pr in dc.Projects
	//                 where pr.ProjectId == projectId
	//                 select pr).Single();

	//            ss = (from pss in dc.ProjectScreenShots
	//                  where pss.ProjectId == p.ProjectId
	//                  select pss).SingleOrDefault();

	//            if (ss == null)
	//            {
	//                ss = new ProjectScreenShot();
	//                p.ProjectScreenShots.Add(ss);
	//            }
	//        }

	//        p.Name = textName;
	//        p.Description = textDescription;
	//        p.SourceCodeUrl = textSourceCodeUrl;
	//        p.FriendlyUrl = textFriendlyUrl;

	//        ss.ProjectId = p.ProjectId;
	//        ss.Image = data;

	//        if (projectId == null || projectId == 0)
	//        {
	//            p.ProjectScreenShots.Add(ss);
	//            dc.Projects.AddObject(p);
	//        }

	//        dc.SaveChanges();

	//        QuickProjectModel m = new QuickProjectModel();

	//        m.Projects = (from proj in dc.Projects
	//                      select proj).ToList();

	//        return View(m);
	//    }

	//    public ActionResult blogentries(int? blogId)
	//    {
	//        RichardsSiteEntities dc = new RichardsSiteEntities();

	//        List<KeyValuePair<int, string>> items = new List<KeyValuePair<int, string>>();

	//        if (blogId == null || blogId == 0)
	//            return RedirectToAction("blogs");

	//        var entries = (from e in dc.BlogEntries
	//                       where e.BlogId == blogId
	//                       orderby e.DateCreated descending
	//                       select e).ToList();

	//        foreach (var e in entries)
	//        {
	//            items.Add(new KeyValuePair<int, string>(e.BlogEntryId, String.Format("{0:dd/MM/yyyy} - {1}", e.DateCreated, e.Title)));
	//        }

	//        return this.Json(items, JsonRequestBehavior.AllowGet);
	//    }

	//    public ActionResult blogentry(int? blogId)
	//    {
	//        RichardsSiteEntities dc = new RichardsSiteEntities();

	//        if (blogId == null || blogId == 0)
	//            return RedirectToAction("blogs");

	//        var entry = (from e in dc.BlogEntries
	//                     where e.BlogEntryId == blogId
	//                     orderby e.DateCreated descending
	//                     select e).Single();

	//        return this.Json(new
	//            {
	//                Title = entry.Title,
	//                Description = entry.BodyHtml,
	//                FriendlyUrl = entry.FriendlyUrl
	//            },
	//            JsonRequestBehavior.AllowGet);
	//    }
	}
}
